<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
include dirname(__FILE__).'/functions.php';
?>
<html>
<head>
	<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php'; ?>
	<?php
		if (isset($_GET['id'])) {
			$id = $_GET['id'];
		}
		if(isset($_POST['submit'])) {
			$content = $_POST['content'];
			$user_id = $_SESSION['user_id'];
			$anId = $_POST['anId'];
			$title = $_POST['title'];
			if(saveOrUpdate($content,$user_id,$anId,$title)) {
				echo '<script type="text/javascript">
						alert("编辑成功！");
					 window.location="index.php";
					 </script>';
			}
		}
	?>				
	<script type="text/javascript" src="../../ckeditor/ckeditor.js"></script>
</head>
<body class="container">
	<div class="row">
		<div>
			<h3>公告具体内容</h3>
		</div>
	<div>

			<form method="post" action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>>
			 	

				    <label for="title" class="control-label">标题</label>
				   
				      <input style="width:200px" required type="text" name="title" class="form-control normal-input" <?php if(isset($id)){
				      		echo "value=";
				      		echo getTitleById($id);	
				      	} ?>  id="title" placeholder="标题">
			
				    <br>
				
		        <textarea id="content" name="content">
		        	<?php
		        		if(isset($id)){
		        		echo getContentById($id);
		        	}
		        	?>
		        </textarea>
		        <script type="text/javascript">
		            CKEDITOR.replace( 'content' , {
		            	width:800,
		            	height:500
		            });
		        </script>
	            <input type="submit" class="btn btn-primary" name="submit" style="margin-top:40px;" value="确认修改" />
	            <input type="hidden" name="anId" <?php
	            	if(isset($id)){
	            	echo 'value='.$id;
	            }
	            ?> >

	    	</form>
		</div>
	</div>
</body>
</html>